<?php include "../public/header.php";?>
<?php include "../public/header_edit.php";?>
<link rel="stylesheet" type="text/css" href="/static/component/laytp/module/cityPicker/city-picker.css">

<body id="optPage">
<form class="layui-form layui-form-pane" id="commentForm">
    <div class="page-title"><div class="page-title-con"><span>编辑租赁设备退场</span><div class="move_title"></div><?php include "../public/sub.php";?></div></div>
    <div class="main-container">

        <div class="block-generic">


            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="edittits"><span>基本信息</span></div>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>退场单号</label>
                        <div class="layui-input-block">
                            <input type="text" id="number" placeholder="请输入" disabled autocomplete="off" class="layui-input disabled">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>项目名称</label>
                        <div class="layui-input-block">
                            <input type="text" readonly id="enginid_name" class="layui-input enginid disabled">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>合同名称</label>
                        <div class="layui-input-block">
                            <input type="text" readonly id="caiid_name" class="layui-input enginid disabled">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label"> 供应商</label>
                        <div class="layui-input-block">
                            <input type="text" id="gonger" disabled autocomplete="off" class="layui-input disabled">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>登记时间</label>
                        <div class="layui-input-block">
                            <input type="text" id="dt" readonly placeholder="请选择" clearable  autocomplete="off" class="layui-input disabled">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">登记人</label>
                        <div class="layui-input-block">
                            <input type="text" id="baner" disabled placeholder="请输入" clearable  autocomplete="off" class="layui-input disabled">
                        </div>
                    </div>
                </div>
            </div>

            <div class="layui-form-item height_auto">
                <div class="short_table_list" key="1">
                    <div class="opt-btn-group">
                        <div><span>退场明细</span></div>
                    </div>
                    <table class="layui-table" lay-size="sm">
                        <thead>
                        <tr>
                            <th width="45">序号</th>
                            <th><text>*</text>设备名称及规格</th>
                            <th>设备编号</th>
                            <th>计数单位</th>
                            <th>进场日期</th>
                            <th>运行量</th>
                            <th><text>*</text>退场日期</th>
                            <th>备注</th>
                        </tr>
                        </thead>
                        <tbody class="short_table_tbody" id="list_list"></tbody>
                    </table>
                    <div class="listerror">提示：<span></span></div>
                </div>
            </div>
        </div>

    </div>
</form>
<script>
    var param_id = getQueryVariable('id') || 0;

    layui.use(['laytp', 'form'], function() {
        var form = layui.form, layer = layui.layer;
        render_input_attr();

        facade.ajax({type: 'get', url: ask_device_mingxi_tui_edit, data:{id:param_id}}).done(function(res){
            if (res.code === 2000) {
                var data = res.data.data;
                var engininfo = res.data.engininfo;
                var caiidinfo = res.data.caiidinfo;
                $("#number").val(data.number);
                $("#enginid_name").val(engininfo.name);
                $("#caiid_name").val(caiidinfo.name);
                $("#gonger").val(caiidinfo.gonger);
                $("#dt").val(data.dt);
                $("#baner").val(data.baner);

                var list = res.data.list;
                var str = '';
                str += '<tr>';
                str += '<td style="width: 45px">1</td>';
                str += '<td>';
                str += '<input type="text" id="'+list.id+'" placeholder="请选择" readonly class="layui-input name disabled" value="'+list.name+'">';
                str += '</td>';
                str += '<td><input type="text" readonly class="layui-input shenum disabled" value="'+list.shenum+'"></td>';
                str += '<td><input type="text" readonly class="layui-input digit disabled" value="'+list.digit+'"></td>';
                str += '<td><input type="text" readonly class="layui-input jindt" value="'+list.jindt+'"></td>';
                str += '<td><input type="text" readonly class="layui-input yununit" value="'+list.yununit+'"></td>';
                str += '<td><input type="text" class="layui-input tuidt bdate_ymd" value="'+list.tuidt+'" ></td>';
                str += '<td><input type="text" class="layui-input explain" value="'+list.explain+'"></td>';
                str += '</tr>';
                $("#list_list").html(str);


                render_from();
                update_refresh_row_func();
                render_from();
            }
        });


        form.on('submit(add)', function(data){

            var list = [''];
            try {
                $('#list_list tr').each(function (i) {
                    var id = $(this).find('.name').attr('id');
                    var tuidt = $(this).find('.tuidt').val();
                    var explain = $(this).find('.explain').val();
                    var index = i + 1;

                    if(!tuidt){
                        throw new Error('第'+index+'行，请选择退场日期');
                    }

                    list.push({
                        id:id,
                        tuidt:tuidt,
                        explain:explain,
                    });
                });
            } catch(e) {
                $(".listerror").find('span').text(e.message);
                $(".listerror").show();
                return false;
            }
            $(".listerror").hide();
            data.field.list = list;



            data = parseMoney(data);
            facade.ajax({url: ask_device_mingxi_tui_edit, data:data.field}).done(function(res){
                if (res.code === 2000) {
                    dataPostTimeOut();
                }
            });

            return false;
        });

    });









    function update_refresh_row_func() {
        render_date();
        render_from();
        $.each($("#list_list").children('tr'),function (key,val) {
            $(this).children('td:first-child').html(key+1);
        });
        setTimeout(function () {
            $(".short_table_list table tbody tr").click(function () {
                $(".short_table_list table tbody tr").removeClass('line-row');
                $(".short_table_list table tbody tr").attr('sle','');
                $(this).addClass('line-row');
                $(this).attr('sle','sle');
            });
        },1000);
    }
</script>
</body>
</html>
